package cn.ljn.system.controller;


import cn.ljn.basic.util.AjaxResult;
import cn.ljn.basic.util.PageList;
import cn.ljn.system.domain.SystemDetail;
import cn.ljn.system.query.SystemDetailQuery;
import cn.ljn.system.service.ISystemDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/detail")
public class SystemDetailController {
    @Autowired
    private ISystemDetailService iSystemDetailService;

    // 查询全部
    @GetMapping
        public List<SystemDetail> findAll(){
            return iSystemDetailService.findAll();
        }

    //查询一个
    @GetMapping("/id")
    public SystemDetail findById(@PathVariable("id") Long id){
        return iSystemDetailService.findById(id);
    }

    @GetMapping("/getSystemDetail/{id}")
        public List<SystemDetail> getDetail(@PathVariable("id") Long id){
                return iSystemDetailService.getDetail(id);
        }

    // 高级查询
    @PostMapping
    public PageList<SystemDetail> queryByPage(@RequestBody SystemDetailQuery systemDetailQuery){
            return iSystemDetailService.queryByPage(systemDetailQuery);
    }
    //删除
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        iSystemDetailService.delete(id);
        return AjaxResult.me().success();
    }
    // 批量删除
    @PatchMapping("/{ids}")
    public AjaxResult batchDelete(@PathVariable("ids") List<Long> ids){
        iSystemDetailService.batchDelete(ids);
        return AjaxResult.me().success();
    }
    // 新增修改
    @PutMapping
    public AjaxResult save(@RequestBody SystemDetail systemDetail){
        if (systemDetail.getId() == null){
            iSystemDetailService.add(systemDetail);
        }else{
            iSystemDetailService.update(systemDetail);
        }
        return AjaxResult.me().success();
    }

}
